#include<bits/stdc++.h>
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define repn(x) rep(x,1,n)
#define pb push_back
inline int read(){int s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57)s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}
using namespace std;
const int N=3e3+5,mod=1e9+7;
inline void add(int &a,int b){((a+=b)>=mod) and (a-=mod);}
inline int Add(int a,int b){return add(a,b),a;}
inline int mul(int a,int b){return 1LL*a*b%mod;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline void red(int &a,int b){add(a,mod-b);}
inline int Red(int a,int b){return red(a,b),a;}
inline int qp(int a,int b){if(!b)return 1;int c=qp(a,b>>1LL);Mul(c,c);if(b&1)Mul(c,a);return c;}
inline int INV(int x){return qp(x,mod-2);}
int n,k,ans,iv2=INV(2),iv6=INV(6);
string s[N];
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
inline bool Che(int X,int Y){
	return X>0&&Y>0&&X<=n&&Y<=n;
}
inline void subtask1(){
	repn(x)repn(y)if(s[x][y]=='.'){
		int fl=0;
		rep(i,0,3){
			int X=x+dx[i],Y=y+dy[i];
			fl|=Che(X,Y)&&s[X][Y]=='#';
		}
		add(ans,fl);
	}
	cout <<ans;
}
inline int C2(int x){
	return mul(x,mul(x-1,iv2));
}
inline int C3(int x){
	return mul(mul(x,x-1),mul(x-2,iv6));
}
bool v[N][N];
inline int getRound(int x,int y){
	int ans=0;
	rep(i,0,3){
		int X=x+dx[i],Y=y+dy[i];
		ans+=Che(X,Y)&&v[X][Y];
	}
	return ans;
}
inline int getRound0(int x,int y){
	int ans=0;
	rep(i,0,3){
		int X=x+dx[i],Y=y+dy[i];
		ans+=Che(X,Y)&&!v[X][Y]&&s[X][Y]=='.';
	}
	return ans;
}
inline void subtask2(){
	int c=0;
	repn(x)repn(y)if(s[x][y]=='.'){
		rep(i,0,3){
			int X=x+dx[i],Y=y+dy[i];
			v[x][y]|=Che(X,Y)&&s[X][Y]=='#';
		}
		add(c,v[x][y]);
	}
	ans=mul(c,mul(c-1,INV(2)));
	repn(x)repn(y)if(v[x][y]){
		rep(i,0,3){
			int X=x+dx[i],Y=y+dy[i];
			if(Che(X,Y)&&s[X][Y]=='.'&&!v[X][Y])add(ans,1);
		}
	}
	cout <<ans;
}
int Ct[N][N],CT[N][N];
inline void subtask3(){
	int c=0;
	repn(x)repn(y)if(s[x][y]=='.'){
		rep(i,0,3){
			int X=x+dx[i],Y=y+dy[i];
			v[x][y]|=Che(X,Y)&&s[X][Y]=='#';
		}
		add(c,v[x][y]);
	}
	ans=C3(c);
	repn(x)repn(y)if(s[x][y]=='.'&&!v[x][y])Ct[x][y]=getRound(x,y);
	repn(x)repn(y)if(s[x][y]=='.'&&!v[x][y]){
		int ct=Ct[x][y];
		add(ans,C2(ct));
		add(ans,mul(ct,c-ct));
	}
	repn(x)repn(y)if(s[x][y]=='.'&&!v[x][y]){
		rep(i,0,1){
			int X=x+dx[i],Y=y+dy[i];
			if(Che(X,Y)&&!v[X][Y]&&s[X][Y]=='.'){
				add(ans,Ct[x][y]+Ct[X][Y]);
			}
		}
	}else if(v[x][y]){
		int c=getRound0(x,y);
		add(ans,C2(c));
	}
	cout <<ans;
}
int iv24=INV(24);
inline int C4(int x){
	return mul(mul(mul(x,x-1),x-2),mul(x-3,iv24));
}
const int Dx[4]={1,1,-1,-1},Dy[4]={1,-1,1,-1};
inline int Ty(int x,int y){
	if(!Che(x,y))return 3;
	if(s[x][y]=='#')return 2;
	return v[x][y];
}
inline void subtask4(){
	int c=0;
	repn(x)repn(y)if(s[x][y]=='.'){
		rep(i,0,3){
			int X=x+dx[i],Y=y+dy[i];
			v[x][y]|=Che(X,Y)&&s[X][Y]=='#';
		}
		add(c,v[x][y]);
	}
	ans=C4(c);
	int tot=0;
	repn(x)repn(y)if(s[x][y]=='.'&&!v[x][y])Ct[x][y]=getRound(x,y);
	else if(v[x][y])CT[x][y]=getRound0(x,y),tot+=CT[x][y];
	repn(x)repn(y)if(s[x][y]=='.'&&!v[x][y]){
		int ct=Ct[x][y];
		add(ans,C3(ct));
		add(ans,mul(C2(ct),c-ct));
		add(ans,mul(ct,C2(c-ct)));
	}
	int S=0;
	repn(x)repn(y)if(v[x][y]){
		int ct=CT[x][y];
		add(S,mul(ct,tot-ct));
	}
	Mul(S,iv2),add(ans,S);
	repn(x)repn(y)if(s[x][y]=='.'&&!v[x][y]){
		int ct=Ct[x][y];
		red(ans,C2(ct));
	}
	rep(x,1,n-1)rep(y,1,n-1){
		int A=Ty(x,y),B=Ty(x,y+1),C=Ty(x+1,y),D=Ty(x+1,y+1);
		if(A==D&&B==C&&A!=B&&A+B==1)red(ans,1);
	}
	repn(x)repn(y)if(s[x][y]=='.'&&!v[x][y]){
		rep(i,0,1){
			int X=x+dx[i],Y=y+dy[i];
			if(Che(X,Y)&&!v[X][Y]&&s[X][Y]=='.'){
				int ct=Ct[x][y]+Ct[X][Y];
				add(ans,mul(ct,c-ct));
				add(ans,C2(Ct[x][y])),add(ans,C2(Ct[X][Y]));
			}
		}
	}
	repn(x)repn(y)if(!Ty(x,y)){
		if(!Ty(x+1,y+1)){
			int Cc=(Ty(x+1,y)==1)+(Ty(x,y+1)==1),Tt=Ct[x][y]+Ct[x+1][y+1]-Cc;
			add(ans,mul(Cc,c-Tt));
		}
		if(!Ty(x+1,y-1)){
			int Cc=(Ty(x+1,y)==1)+(Ty(x,y-1)==1),Tt=Ct[x][y]+Ct[x+1][y-1]-Cc;
			add(ans,mul(Cc,c-Tt));
		}
		if(!Ty(x,y+2)){
			int Cc=(Ty(x,y+1)==1),Tt=Ct[x][y]+Ct[x][y+2]-Cc;
			add(ans,mul(Cc,c-Tt));
		}
		if(!Ty(x+2,y)){
			int Cc=(Ty(x+1,y)==1),Tt=Ct[x][y]+Ct[x+2][y]-Cc;
			add(ans,mul(Cc,c-Tt));
		}
	}
	repn(x)repn(y)if(!Ty(x,y)){
		int A,B,ct=Ct[x][y];
		A=Ty(x+1,y),B=Ty(x+2,y);
		if(!A&&!B)add(ans,ct+Ct[x+1][y]+Ct[x+2][y]);
		if(!A&&B==1)add(ans,CT[x+2][y]-1);
		A=Ty(x,y+1),B=Ty(x,y+2);
		if(!A&&!B)add(ans,ct+Ct[x][y+1]+Ct[x][y+2]);
		if(!A&&B==1)add(ans,CT[x][y+2]-1);
		A=Ty(x+1,y),B=Ty(x+1,y+1);
		if(!A&&!B)add(ans,ct+Ct[x+1][y]+Ct[x+1][y+1]-(Ty(x,y+1)==1));
		if(!A&&B==1)add(ans,CT[x+1][y+1]-1-(Ty(x,y+1)==0));
		B=Ty(x,y+1);
		if(!A&&!B)add(ans,ct+Ct[x+1][y]+Ct[x][y+1]-(Ty(x+1,y+1)==1));
		if(!A&&B==1)add(ans,CT[x][y+1]-1-(Ty(x+1,y+1)==0));
		if(!B&&A==1)add(ans,CT[x+1][y]-1-(Ty(x+1,y+1)==0));
		A=Ty(x+1,y+1);
		if(!A&&!B)add(ans,ct+Ct[x][y+1]+Ct[x+1][y+1]-(Ty(x+1,y)==1));
		if(!B&&A==1)add(ans,CT[x+1][y+1]-1-(Ty(x+1,y)==0));
		A=Ty(x-1,y+1);
		if(!A&&!B)add(ans,ct+Ct[x-1][y+1]+Ct[x][y+1]-(Ty(x-1,y)==1));
		if(!B&&A==1)add(ans,CT[x-1][y+1]-1-(Ty(x-1,y)==0));
		A=Ty(x-1,y),B=Ty(x-2,y);
		if(!A&&B==1)add(ans,CT[x-2][y]-1);
		A=Ty(x,y-1),B=Ty(x,y-2);
		if(!A&&B==1)add(ans,CT[x][y-2]-1);
		A=Ty(x-1,y),B=Ty(x,y-1);
		if(!A&&B==1)add(ans,CT[x][y-1]-1-(Ty(x-1,y-1)==0));
		A=Ty(x+1,y);
		if(!A&&B==1)add(ans,CT[x][y-1]-1-(Ty(x+1,y-1)==0));
		A=Ty(x-1,y),B=Ty(x,y+1);
		if(A==1&&!B)add(ans,CT[x-1][y]-1-(Ty(x-1,y+1)==0));
	}
	repn(x)repn(y)if(v[x][y])add(ans,C3(CT[x][y]));
	cout <<ans;
}
inline void Main(){
	n=read(),k=read();
	repn(i)cin>>s[i],s[i]='*'+s[i];
	if(k==1)return subtask1();
	if(k==2)return subtask2();
	if(k==3)return subtask3();
	if(k==4)return subtask4();
}
signed main(){
	freopen("brick.in","r",stdin);
	freopen("brick.out","w",stdout);
	int T=1;
	while(T--)Main();
	return 0;
}
